package com.auto.api.core.type.json.torna;

import cn.torna.sdk.param.DocParamResp;
import com.auto.api.common.utils.JsonMapper;
import com.auto.api.core.constants.MappingConstants;
import com.auto.api.core.util.BeanUtil;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.ResolvableType;

/**
 * @program:
 * @description: TornaObjectApiResultJsonTypeHandler类型处理器
 * @author: liangshf
 * @create: 2020-09-24
 */
public class TornaObjectApiResultJsonTypeHandler extends AbstractTornaApiResultJsonTypeHandler {

    private static final Logger logger = LoggerFactory.getLogger(TornaObjectApiResultJsonTypeHandler.class);

    @Override
    public boolean canCovert(ResolvableType resolvableType) {
        return resolvableType.resolve().getSimpleName().equals(MappingConstants.OBJECT);
    }

    @Override
    public String getResultJson(ResolvableType resolvableType, List<DocParamResp> responseParams){
        logger.warn("resultClass is error：{}", resolvableType.getType().getTypeName());
        DocParamResp data = BeanUtil.getDocResponseResp(MappingConstants.OBJECT, MappingConstants.EMPTY_STRING, MappingConstants.OBJECT);
        data.setExample(MappingConstants.OBJECT);
        responseParams.add(data);
        return JsonMapper.toJson(responseParams);
    }
}